package copyengine.ui.component.progressbar.animation
{
	import flash.display.MovieClip;
	import flash.geom.Matrix;

	public final class CEMProgressMaskAnimation implements ICEProgressBarAnimation
	{
		//水平
		private static const PROGRESS_DIRECTION_HORIZONTAL:int=1;
		//垂直
		private static const PROGRESS_DIRECTION_VERTICAL:int=2;

		private var targetMaskMc:MovieClip;

		private var maskMcDefaultWidth:Number;
		private var maskMcDefaultHeight:Number;
		private var maskDefaultXPos:Number;
		private var maskDefaultYPos:Number;
		private var direction:int;

		public function CEMProgressMaskAnimation()
		{
		}

		public function setTarget(_progressBarMc:MovieClip):void
		{
			//使用maskMc作为进度条遮罩的key值
			targetMaskMc=_progressBarMc["maskMc"];

			//读取遮罩默认的宽高信息
			maskMcDefaultWidth=targetMaskMc.width;
			maskMcDefaultHeight=targetMaskMc.height;
			maskDefaultXPos=targetMaskMc.x;
			maskDefaultYPos=targetMaskMc.y;

			//检测遮罩的方向
			direction=targetMaskMc.width > targetMaskMc.height ? PROGRESS_DIRECTION_HORIZONTAL : PROGRESS_DIRECTION_VERTICAL
		}

		public function setProgressPercent(_precent:Number):void
		{
			if (direction == PROGRESS_DIRECTION_HORIZONTAL)
			{
				targetMaskMc.width=maskMcDefaultWidth * 0.01 * _precent;
				targetMaskMc.x=maskDefaultXPos + (targetMaskMc.width - maskMcDefaultWidth) / 2;
			}
			else
			{
				targetMaskMc.height=maskMcDefaultHeight * 0.01 * _precent;
			}
		}

		public function dispose():void
		{
			targetMaskMc=null;
		}

	}
}
